﻿using System;
using System.Collections.Generic;

namespace oueb.react
{
    public static class MimeTypes
    {
        public static void SetMimeType(string ext, string mimetype)
        {
            MIME_TYPES[ext] = mimetype;
        }
        public static bool Try(string filename, out string mimetype)
        {
            var ext = filename.Substring(filename.LastIndexOf('.'));
            if (MIME_TYPES.ContainsKey(ext))
            {
                mimetype = MIME_TYPES[ext];
                return true;
            }
            mimetype = string.Empty;
            return false;
        }
        internal static IDictionary<string, string> MIME_TYPES = new Dictionary<string, string>()
        {
            [".txt"] = "text/plain",
            [".html"] = "text/html",
            [".htm"] = "text/html",
            [".css"] = "text/css",
            [".js"] = "text/javascript",
            [".mjs"] = "text/javascript",
            [".json"] = "application/json",
            [".png"] = "image/png",
            [".jpeg"] = "image/jpeg",
            [".jpg"] = "image/jpeg",
            [".gif"] = "image/gif",
            [".svg"] = "image/svg+xml",
            [".webp"] = "image/webp",
            [".ico"] = "image/vnd.microsoft.icon",
            [".tif"] = "image/tiff",
            [".tiff"] = "image/tiff",
            [".bmp"] = "image/bmp",
            [".avif"] = "image/avif",
            [".apng"] = "image/apng",
            [".mp3"] = "audio/mpeg",
            [".aac"] = "audio/aac",
            [".wav"] = "audio/wav",
            [".ogg"] = "audio/ogg",
            [".opus"] = "audio/ogg",
            [".weba"] = "audio/webm",
            [".mp4"] = "video/mp4",
            [".mpeg"] = "video/mpeg",
            [".mpg"] = "video/mpeg",
            [".webm"] = "video/webm",
            [".ogv"] = "video/ogg",
            [".oga"] = "audio/ogg",
            [".avi"] = "video/x-msvideo",
            [".3gp"] = "video/3gpp",
            [".3g2"] = "video/3gpp2",
            [".ts"] = "video/mp2t",
            [".ttf"] = "font/ttf",
            [".otf"] = "font/otf",
            [".woff"] = "font/woff",
            [".woff2"] = "font/woff2",
            [".zip"] = "application/zip",
            [".gz"] = "application/gzip",
            [".bz"] = "application/x-bzip",
            [".bz2"] = "application/x-bzip2",
            [".tar"] = "application/x-tar",
            [".rar"] = "application/vnd.rar",
            [".7z"] = "application/x-7z-compressed",
            [".arc"] = "application/x-freearc",
            [".pdf"] = "application/pdf",
            [".doc"] = "application/msword",
            [".docx"] = "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
            [".xls"] = "application/vnd.ms-excel",
            [".xlsx"] = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
            [".ppt"] = "application/vnd.ms-powerpoint",
            [".pptx"] = "application/vnd.openxmlformats-officedocument.presentationml.presentation",
            [".odt"] = "application/vnd.oasis.opendocument.text",
            [".ods"] = "application/vnd.oasis.opendocument.spreadsheet",
            [".odp"] = "application/vnd.oasis.opendocument.presentation",
            [".rtf"] = "application/rtf",
            [".epub"] = "application/epub+zip",
            [".md"] = "text/markdown",
            [".xml"] = "application/xml",
            [".csv"] = "text/csv",
            [".ics"] = "text/calendar",
            [".webmanifest"] = "application/manifest+json",
            [".vsd"] = "application/vnd.visio",
            [".azw"] = "application/vnd.amazon.ebook",
            [".jar"] = "application/java-archive",
            [".php"] = "application/x-httpd-php",
            [".xul"] = "application/vnd.mozilla.xul+xml",
            [".mpkg"] = "application/vnd.apple.installerxml",
            [".bin"] = "application/octet-stream"
        };
    }
}
